﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Services;
using kysec_MVC.Models;

namespace kysec_MVC.Controllers
{
    public class LoginController : Controller
    { 
        public ActionResult Login()
        {
            return View("Login");
        } 

        /// <summary>
        /// 用户登录的判断，返回json格式的数据
        /// </summary>
        [HttpPost]
        public bool Login(kysec.RAL.EFToMySql.tb_user model)
        {
            bool jsonStr = false;//定义返回的json格式

            kysec.Bll.User.Login.AddFirstUser();
            jsonStr = kysec.Bll.User.Login.LoginIsOk(model);

            return jsonStr;
            //if (jsonStr)
            //{
            //    //Server.Transfer(kysec.CR.MyUrl.WebData.WEBURL + "/Login/Index");
            //    //Response.Redirect("~/Login/Index");
            //    //return RedirectToAction("Index", "Login");
            //}
            //else {
            //    string msg = string.Format("<script type='text/javascript'>alert({0});</script>", "用户名或密码错误");
            //    Response.Write(msg);
            //    //return View();
            //}
        }

        
        /// <summary>
        /// 退出系统时，设置其OnLine状态为false
        /// </summary>
        [HttpPost]
        public void ExitSystem(string username)
        {
            kysec.Bll.User.Login.ExitSystem(username);          
        }
        /// <summary>
        /// 进入后台首页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View("Index");
        }

        public ActionResult Index_top()
        {
            return View("Index_top");
        }
        public ActionResult Index_left()
        {
            return View();
        }
        public ActionResult Index_right()
        {
            return View();
        }

        public ActionResult BackHome()
        {
            return View();
        }
        /// <summary>
        /// 退出登录后的界面
        /// </summary>
        /// <returns></returns>
        public ActionResult Exit()
        {
            return View("Exit");
        }
    }
}
